package org.gd.hellojson.gson.reg;

import com.google.gson.*;

import java.util.HashMap;
import java.util.Map;

public class App {

    public static void main(String...a) {
        Gson gson = new Gson();
        Map<String, String> data = new HashMap<String, String>();
        data.put("res", "ok");
        JsonObject res = new JsonObject();
        JsonObject info = new JsonObject();
        info.addProperty("state", "ok");
        info.addProperty("code", 0);
        info.addProperty("msg", "");
        res.add("result", info);
        res.add("data", gson.toJsonTree(data));
        String json = res.toString();
        System.out.println(json);



        JsonElement jElement = new JsonParser().parse(json);
        JsonObject jObject = jElement.getAsJsonObject();
        System.out.println(jObject.toString());
        System.out.println(jObject.get("result").toString());

        System.out.println(jObject.get("result").getAsJsonObject().get("state").getAsString());

        /*
        JsonArray jArray = jObject.getAsJsonArray("translations");
        jObject = jArray.get(0).getAsJsonObject();
        String result = jObject.get("translatedText").toString();
        */



        System.out.println("{\"result\":{\"state\":\"ok\",\"code\":0,\"msg\":\"\"},\"data\":null}");
    }
}
